package com.jx.dao.statistics;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jx.pojo.entity.statistics.ArticleVisitsStat;
import com.jx.pojo.po.statistics.ArticleVisitsPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface ArticleVisitsStatDao extends BaseMapper<ArticleVisitsStat> {

    @Update("INSERT INTO article_visits_stat (article_id, visits) VALUES ( #{articleId}, 1)ON DUPLICATE KEY UPDATE visits = visits + 1;")
    void increaseArticleVisits(@Param("articleId") Integer articleId);

    @Select("select a.title,av.visits from article_visits_stat av,article a where av.article_id = a.id order by visits desc limit #{n}")
    List<ArticleVisitsPO> countArticleVisits(@Param("n") Integer n);
}
